package cn.tedu.scalabasic

import scala.collection.immutable

/**
 * @author Amos
 * @date 2022/5/17
 */

object ProcessControllFor {
  def main(args: Array[String]): Unit = {
    // 1到10的循环，for，until
    for (i <- 1 until 10) {
      println(i)
    }

    for (i <- Range(1, 10, 2)) {
      println(i)
    }

    // 九九乘法表
    for (i <- 1 to 9) {
      for (j <- 1 to i) {
        print(s"${j} * ${i} = ${i * j}\t")
      }
      println()
    }

    println("*" * 50)

    for (i <- 1 to 9; j <- 1 to i) {
      print(s"${j} * ${i} = ${i * j}\t")
      if (i == j) println
    }

    // 守卫模式，求1到10的偶数
    for (i <- 1 to 10 if i % 2 == 0) {
      println(i)
    }

    // 推导式:保留for循环的结果
    val result = for (i <- 1 to 10 if i % 2 == 0) yield {
      i + 10
    }
    println(result)


  }
}
